package com.qsl.ssyx.acl.controller;


import com.qsl.ssyx.acl.service.PermissionService;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.acl.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-08
 */
@Api(tags = "权限接口")
@RestController
@RequestMapping("/admin/acl/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @ApiOperation("懒查询-树形结构数据")
    @GetMapping("/getChildrenPermission")
    public Result selectPage() {
        List<Permission> model = permissionService.selectPage();
        return Result.ok(model);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody Permission permission) {

        boolean flag = permissionService.save(permission);
        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询")
    @PostMapping("getById/{Id}")
    public Result save(@ApiParam(value = "Id") @PathVariable Integer Id) {
        Permission permission = permissionService.getById(Id);
        return Result.ok(permission);
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody Permission permission) {
        boolean flag = permissionService.updateById(permission);
        return Result.ok(flag);
    }

    @ApiOperation("删除-递归删除")
    @DeleteMapping("remove/{Id}")
    public Result remove(@ApiParam("id") @PathVariable Integer Id) {

        boolean flag = permissionService.removeChildById(Id);
        return Result.ok(flag);
    }


}

